package com.liuyi.netty.mqtt.common.helper;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 线程连接池
 *
 * @author Mr.Fmy
 * @since 2021-09-10
 */
@Slf4j
public class ThreadFactoryImpl implements ThreadFactory {

    private AtomicInteger num = new AtomicInteger(1);

    private String name;

    public ThreadFactoryImpl(String name) {
        this.name = name;
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread t = new Thread(r, this.name + "-" + num.getAndIncrement());
        return t;
    }
}
